package com.pureut.system.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.system.domain.dto.OfConfigDTO;
import com.pureut.system.domain.SysOfConfig;
import com.pureut.system.domain.SysOfValue;
import com.pureut.system.service.ISysOfConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 编码生成变量控制层
 * @Param
 * @return
 * @Date 22-11-16
 * @Author hl
 **/
@RestController
@RequestMapping("/ofconfig")
public class SysOfConfigController extends BaseController {
    @Autowired
    private ISysOfConfigService sysOfConfigService;


    /**
     * 获取编码配置
     */
    @RequiresPermissions("system:ofconfig:list")
    @GetMapping("/list")
    public OfConfigDTO list()
    {
        return sysOfConfigService.selectOfConfigList();
    }

    /**
     * 根据编号获取详细信息
     */
    @RequiresPermissions("system:ofconfig:query")
    @GetMapping(value = "/{configId}")
    public AjaxResult getInfo(@PathVariable long configId)
    {
        AjaxResult ajax = AjaxResult.success();
        List<SysOfValue> list= sysOfConfigService.selectofConfigById(configId);
        ajax.put("detailed", list);
        return ajax;
    }

    /**
     * 新增编码变量
     */
    @RequiresPermissions("system:ofconfig:add")
    @Log(title = "变量新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysOfConfig sysOfConfig) throws Exception {
        return toAjax(sysOfConfigService.sysOfConfigAdd(sysOfConfig));
    }

    /**
     * 删除编码
     */
    @RequiresPermissions("system:ofconfig:remove")
    @Log(title = "删除配置变量", businessType = BusinessType.DELETE)
    @DeleteMapping("/{configId}")
    public AjaxResult remove(@PathVariable("configId") long configId) throws Exception {
        return toAjax(sysOfConfigService.deleteOfConfigById(configId));
    }


    /**
     * 修改配置
     */
    @RequiresPermissions("system:ofconfig:edit")
    @Log(title = "修改配置变量", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody SysOfConfig sysOfConfig) throws Exception {
        return toAjax(sysOfConfigService.updateOfConfigEdit(sysOfConfig));
    }


    /**
     * 获取下拉
     */
    @GetMapping("/dropVariablesThe")
    public AjaxResult dropVariablesThe(int configType)
    {
        AjaxResult ajax = AjaxResult.success();
        ajax.put("theDrop", sysOfConfigService.dropVariablesThe(configType));
        return ajax;
    }


}
